#include <panic.h>
#include <ps.h>
#include <string.h>
#include <boot.h>
#include "system.h"

typedef enum
{
    SYSTEM_PS_SETTING =  30
} SYSTEM_PS_KEY_T;

typedef struct
{
    uint8 bootMode;
    uint8 gain;
} SETTING_T;

typedef struct
{
    SETTING_T setting;
} SYSTEM_DATA_T;

SYSTEM_DATA_T SYSTEM_RUNDATA;

void SystemInit(void)
{
    if (!PsRetrieve(SYSTEM_PS_SETTING, &SYSTEM_RUNDATA.setting, sizeof(SETTING_T)/2))
    {
        /* Default setting */
        SYSTEM_RUNDATA.setting.bootMode = BOOT_MODE_SOURCE;

        PsStore(SYSTEM_PS_SETTING, &SYSTEM_RUNDATA.setting, sizeof(SETTING_T)/2);
    }
}

uint8 SystemGetRunningMode(void)
{
    return SYSTEM_RUNDATA.setting.bootMode;
}

void SystemSetRunningMode(uint8 mode)
{
    if(SYSTEM_RUNDATA.setting.bootMode != mode)
    {
        SYSTEM_RUNDATA.setting.bootMode = mode;

        PsStore(SYSTEM_PS_SETTING, &SYSTEM_RUNDATA.setting, sizeof(SETTING_T)/2);
    }
}



